import request from "@/utils/request.js"

export const getListAPI = () => {
  return request({
    url: 'http://geek.itheima.net/v1_0/channels'
  })
}

//注册功能
export const registerAPI=({username,password,repassword})=>{
  return request({
    url:"/api/reg",
    method:'post',
    data:{
      username,
      password,
      repassword
    }
  })
}
//登录功能
export const loginAPI=(({username,password})=>{
  return request({
    url:"/api/login",
    method:'post',
    data:{
      username,
      password
    }
  })
})

//获取用户信息
export const getUserInfoAPI=()=>{
  return request({
    url:"/my/userinfo",
  })
}

//获取菜单信息
export const getMenuListAPI=()=>{
  return request({
    url:"/my/menus",
  })
}

//更新用户信息
export const updateUserInfoAPI=({id,username,nickname,email,user_pic})=>{
  return request({
    url:'/my/userinfo',
    method:'put',
    data:{
      id,
      username,
      nickname,
      email,
      user_pic
    }
  })
}

//更新用户头像
export const updateUserPicAPI=(avatar)=>{
  return request({
    url:"/my/update/avatar",
    method:"patch",
    data:{
      avatar
    }
  })
}

//修改用户密码
export const updatePwdAPI=({old_pwd,new_pwd,re_pwd})=>{
  return request({
    url:"/my/updatepwd",
    method:"patch",
    data:{
      old_pwd,
      new_pwd,
      re_pwd
    }
  })
}

//获取文章分类
export const getCateListAPI= ()=>{
  return request({
    url:"/my/cate/list"
  })
}
//新增文章分类
export const saveCateAPI=({cate_name,cate_alias})=>{
  return request({
    url:"/my/cate/add",
    data:{
      cate_name,
      cate_alias
    },
    method:"post"
  })
}

//修改文章分类
export const updateCateAPI=({id,cate_name,cate_alias}) =>{
  return request({
    url:"/my/cate/info",
    method:"put",
    data:{
      id,
      cate_name,
      cate_alias
    }
  })
}
//删除文章分类
export const delCateAPI=(id)=>{
  return request({
    url:"/my/cate/del",
    method:"delete",
    params:{
      id
    }
  })
}

//发布新文章
export const pubNewArtAPI=(fd)=>{
  return request({
    url:"/my/article/add",
    method:'post',
    data:fd
  })
}

//获取文章数据
export const getArtListAPI=({pagenum,pagesize,cate_id,state})=>{
  return request({
    url:"/my/article/list",
    params:{
      pagenum,
      pagesize,
      cate_id,
      state,
    }
  })
}

//依据Id获得文章详细内容
export const getArtDetailAPI=(id)=>{
  return request({
    url:"/my/article/info",
    params:{
      id
    }
  })
}
//依据id删除文章内容
export const deleteArtByIdAPI=(id)=>{
  return request({
    url:"/my/article/info",
    method:'DELETE',
    params:{id}
  })
}